﻿using System;
using System.Collections.Generic;
using System.Web;
using PayRoller.Code;
using System.Web.SessionState;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using HySoft.Cash.Business;
using HySoft.Cash.Structure;
using System.Configuration;
using System.Web.Profile;
using HySoft.Cash;


namespace PayRoller.Manage.OrgInfo
{
    public class OrgAdd : ParentPage, IRequiresSessionState
    {
        // Fields
        protected Button Button1;
        protected HtmlForm form1;
        protected HtmlHead Head1;
        protected Label lblTip;
        protected TextBox txtABN;
        protected TextBox txtContactPerson;
        protected TextBox txtContactPhone1;
        protected TextBox txtExpCreditLimit;
        protected TextBox txtFax;
        protected TextBox txtIndustry;
        protected TextBox txtOfficeAddress;
        protected TextBox txtOrgName;
        protected TextBox txtPassWord;
        protected TextBox txtPassWord2;
        protected TextBox txtPreferredEmail;
        protected TextBox txtsPosition;
        protected TextBox txtTradingName;
        protected TextBox txtUserName;

        // Methods
        protected void Button1_Click(object sender, EventArgs e)
        {
            TorginfoBN obn = new TorginfoBN(this.Page);
            obn.QueryUserName(this.txtUserName.Text);
            if (obn.GetList().Rows.Count <= 0)
            {
                try
                {
                    TorginfoDT detail = new TorginfoDT();
                    detail.AgreementDate = SafeDateTime.LocalNow;
                    detail.RegDate = SafeDateTime.LocalNow;
                    detail.OrgName = this.txtOrgName.Text;
                    detail.TradingName = this.txtTradingName.Text;
                    detail.ABN = this.txtABN.Text;
                    detail.Industry = this.txtIndustry.Text;
                    detail.OfficeAddress = this.txtOfficeAddress.Text;
                    detail.WebSite = "";
                    detail.ContactPerson = this.txtContactPerson.Text;
                    detail.sPosition = this.txtsPosition.Text;
                    detail.ExpCreditLimit = Convert.ToDecimal(this.txtExpCreditLimit.Text);
                    detail.PostalAddress = "";
                    detail.ContactPhone1 = this.txtContactPhone1.Text;
                    detail.ContactPhone2 = "";
                    detail.Fax = this.txtFax.Text;
                    detail.Mobile = "";
                    detail.PreferredEmail = this.txtPreferredEmail.Text;
                    detail.AltEmail1 = "";
                    detail.AltEmail2 = "";
                    detail.UserName = this.txtUserName.Text;
                    detail.PassWord = this.txtPassWord.Text;
                    detail.IsValid = OrginfoStatuses.Normal;
                    detail.CreditLimit = 0M;
                    detail.FeeBalance = 0M;
                    detail.AvailableBalance = 0M;
                    if (obn.Add(detail))
                    {
                        obn.Dispose();
                        obn = null;
                        base.ClientScript.RegisterStartupScript(base.GetType(), "", "<script>alert('Success!');window.location='OrgList.aspx'</script>");
                    }
                    else
                    {
                        obn.Dispose();
                        obn = null;
                    }
                }
                catch (Exception exception)
                {
                    this.lblTip.Text = exception.Message;
                }
            }
            else
            {
                base.ClientScript.RegisterStartupScript(base.GetType(), "", "<script>alert('对不起,该用户已经存在!');</script>");
            }
        }

        protected override void OnInit(EventArgs e)
        {
            base.m_ModuleCode = "0003";
            base.CheckLogin(true);
            base.CheckPerm();
            base.OnInit(e);
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            this.Button1.Attributes.Add("onclick", "return Check();");
        }

        // Properties
        protected HttpApplication ApplicationInstance
        {
            get
            {
                return this.Context.ApplicationInstance;
            }
        }

        protected DefaultProfile Profile
        {
            get
            {
                return (DefaultProfile)this.Context.Profile;
            }
        }
    }

}
